/*
 * Digital Audio Mobile - A multi track studio for Windows Mobile
 * Copyright (C) 2008 David Olsson
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "Composition.h"
#include "Track.h"

using namespace std;

Composition::Composition() throw(): m_bpm(120), m_sigBpm(4), m_sigBnt(4), m_trackCount(1) {
}

Composition::~Composition() {
    for(list<Track *>::iterator iter = m_tracks.begin(); iter != m_tracks.end(); iter++) {
        delete(*iter);
    }
}

unsigned int Composition::beatsPerMinute() const throw() {
    return(m_bpm);
}

void Composition::setBeatsPerMinute(unsigned int bpm) throw() {
    m_bpm = bpm;
}

unsigned int Composition::beatsPerMeasure() const throw() {
    return(m_sigBpm);
}

void Composition::setBeatsPerMeasure(unsigned int bpm) throw() {
    m_sigBpm = bpm;
}

unsigned int Composition::beatNoteType() const throw() {
    return(m_sigBnt);
}

void Composition::setBeatNoteType(unsigned int bnt) throw() {
    m_sigBnt = bnt;
}

Track *Composition::addTrack() throw() {
    TCHAR nameBuf[128];
    wsprintf(nameBuf, TEXT("Track %d"), m_trackCount++);
    Track *track = new Track(nameBuf);
    m_tracks.push_back(track);
    return(track);
}

void Composition::removeTrack(Track *track) throw() {
    track->unlinkSegments();
    delete(track);
    m_tracks.remove(track);
}

unsigned int Composition::numTracks() const throw() {
    return(m_tracks.size());
}

const list<Track *> &Composition::tracks() const throw() {
    return(m_tracks);
}

list<Track *> &Composition::tracks() throw() {
    return(m_tracks);
}
